const Sequelize = require('sequelize');

/**
 * 用户账号表
 */
exports.UsersAccounts = {
    domain: {type: Sequelize.STRING(160), allowNull: false, comments: '域名'},
    nickname: {type: Sequelize.STRING(160), allowNull: true, comments: '别名'},
    username: {type: Sequelize.STRING(160), allowNull: false, comments: '登录账号'},
    password: {type: Sequelize.STRING(160), allowNull: true, comments: '登录密码'},
    cookies: {type: Sequelize.TEXT, allowNull: true, comments: 'cookie内容'},
    ext_data: {type: Sequelize.TEXT, allowNull: true, comments: '扩展数据'},
    status: {
        type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Pending',
        validate: {isIn: [['Pending', 'Active', 'Deactivated']]}
    },
    note: {type: Sequelize.STRING(160), allowNull: true, comments: '备注'},
    user_id: {
        type: Sequelize.INTEGER, references: {model: 'Users', key: 'id'}, allowNull: false
    }
}

/**
 * 用户账号日志表
 */
exports.UsersAccountsLogs = {
    opt: {type: Sequelize.STRING(100), allowNull: true, comments: '操作'},
    is_success: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '是否成功'},
    domain: {type: Sequelize.STRING(160), allowNull: true, comments: '域名'},
    username: {type: Sequelize.STRING(160), allowNull: true, comments: '登录账号'},
    user_id: {type: Sequelize.INTEGER, allowNull: true, comments: '操作人员'},
    ext_data: {type: Sequelize.TEXT, allowNull: true, comments: '扩展数据'},
}

/**
 * 用户设置表
 */
exports.UsersSettings = {
    type: {type: Sequelize.STRING(160), allowNull: true, comments: '类型'},
    pid: {type: Sequelize.STRING(160), allowNull: true, comments: '淘宝联盟pid'},
    we_id: {type: Sequelize.STRING(160), allowNull: true, comments: '微信分享模板编号'},
    qq_id: {type: Sequelize.STRING(160), allowNull: true, comments: 'QQ分享模板编号'},
    ext_data: {type: Sequelize.TEXT, allowNull: true, comments: '扩展数据'},
    order_by: {type: Sequelize.INTEGER(9), allowNull: false, defaultValue: 0},
    user_id: {
        type: Sequelize.INTEGER, references: {model: 'Users', key: 'id'}, allowNull: false
    }
}

/**
 * 用户发送信息
 */
exports.UsersTexts = {
    openid: {type: Sequelize.STRING(50), allowNull: true},
    text: {type: Sequelize.TEXT, allowNull: true, comments: '内容'},
};

/**
 * 给用户发送的信息
 */
exports.ToUsersTexts = {
    openid: {type: Sequelize.STRING(50), allowNull: true},
    text: {type: Sequelize.TEXT, allowNull: true, comments: '内容'},
    admin_id: {
        type: Sequelize.INTEGER, allowNull: true, comments: '消息发送者'
    }
};

/**
 * 收藏表
 */
exports.UsersCollections = {
    goods_id: {type: Sequelize.STRING(160), allowNull: true, comments: '商品编号', unique: 'goods_user'},
    user_id: {
        type: Sequelize.INTEGER, references: {model: 'Users', key: 'id'}, allowNull: false, unique: 'goods_user'
    },
    source: {type: Sequelize.STRING(100), allowNull: true, comments: '来源'}
};

/**
 * 浏览表
 */
exports.UsersViews = {
    goods_id: {type: Sequelize.STRING(160), allowNull: true, comments: '商品编号', unique: 'goods_user'},
    user_id: {
        type: Sequelize.INTEGER, references: {model: 'Users', key: 'id'}, allowNull: false, unique: 'goods_user'
    },
    agency_id: {type: Sequelize.INTEGER, allowNull: true, comments: '上级代理编号'},
    source: {type: Sequelize.STRING(100), allowNull: true, comments: '来源'}
};

/**
 * 搜索表
 */
exports.UsersSearchs = {
    keyword: {type: Sequelize.STRING(160), allowNull: true, comments: '商品编号', unique: 'keyword_goods_user'},
    goods_id: {type: Sequelize.STRING(160), allowNull: true, comments: '商品编号', unique: 'keyword_goods_user'},
    user_id: {
        type: Sequelize.INTEGER, references: {model: 'Users', key: 'id'}, allowNull: false, unique: 'keyword_goods_user'
    },
    agency_id: {type: Sequelize.INTEGER, allowNull: true, comments: '上级代理编号'},
    source: {type: Sequelize.STRING(100), allowNull: true, comments: '来源'}
};

/**
 * 分享表
 */
exports.UsersShares = {
    goods_id: {type: Sequelize.STRING(160), allowNull: true, comments: '商品编号'},
    user_id: {
        type: Sequelize.INTEGER, references: {model: 'Users', key: 'id'}, allowNull: false
    },
    ext_data: {type: Sequelize.TEXT, allowNull: true, comments: '扩展数据'},
    source: {type: Sequelize.STRING(100), allowNull: true, comments: '来源'}
};

/**
 * 申请
 */
exports.EventApplies = {
    user_id: {type: Sequelize.INTEGER, allowNull: true, comments: '用户编号'},
    tao_user: {type: Sequelize.STRING(160), allowNull: true, comments: '淘宝用户名', unique: 'tao_user_goods_id'},
    goods_id: {type: Sequelize.STRING(160), allowNull: true, comments: '商品编号', unique: 'tao_user_goods_id'},
    pid: {type: Sequelize.STRING(160), allowNull: true, comments: '淘宝联盟pid'},

    commissionRate: {type: Sequelize.DECIMAL(10, 2), allowNull: true},
    CampaignID: {type: Sequelize.INTEGER, allowNull: true},
    CampaignName: {type: Sequelize.STRING(190), allowNull: true},
    AvgCommission: {type: Sequelize.STRING(190), allowNull: true},
    manualAudit: {type: Sequelize.INTEGER(1), allowNull: true},
    ShopKeeperID: {type: Sequelize.INTEGER, allowNull: true}
}

/**
 * 申请失败
 */
exports.EventFails = {
    user_id: {type: Sequelize.INTEGER, allowNull: true, comments: '用户编号'},
    tao_user: {type: Sequelize.STRING(160), allowNull: true, comments: '淘宝用户名'},
    goods_id: {type: Sequelize.STRING(160), allowNull: true, comments: '商品编号'},
    ext_data: {type: Sequelize.TEXT, allowNull: true, comments: '扩展数据'}
}

/**
 * 京东推广申请
 */
exports.JDEventApplies = {
    user_id: {type: Sequelize.INTEGER, allowNull: true, comments: '用户编号'},
    jd_user: {type: Sequelize.STRING(160), allowNull: true, comments: '京东用户名', unique: 'user_pid_goods_id'},
    jd_pid: {type: Sequelize.STRING(160), allowNull: true, comments: '京东pid', unique: 'user_pid_goods_id'},
    goods_id: {type: Sequelize.STRING(160), allowNull: true, comments: '商品编号', unique: 'user_pid_goods_id'},

    urlAdvCode: {type: Sequelize.STRING(190), allowNull: true},
    shotCode: {type: Sequelize.STRING(190), allowNull: true}
}

/**
 * 京东推广申请失败
 */
exports.JDEventFails = {
    user_id: {type: Sequelize.INTEGER, allowNull: true, comments: '用户编号'},
    jd_user: {type: Sequelize.STRING(160), allowNull: true, comments: '京东用户名'},
    jd_pid: {type: Sequelize.STRING(160), allowNull: true, comments: '京东pid'},
    goods_id: {type: Sequelize.STRING(160), allowNull: true, comments: '商品编号'},
    ext_data: {type: Sequelize.TEXT, allowNull: true, comments: '扩展数据'}
}

/**
 * 代理申请的优惠券码
 */
exports.AgencysCoupons = {
    agency_id: {type: Sequelize.INTEGER, allowNull: true, comments: '用户编号'},
    agency_pid: {type: Sequelize.STRING(160), allowNull: true, comments: '申请的pid', unique: 'agency_pid_goods_id'},
    goods_id: {type: Sequelize.STRING(160), allowNull: true, comments: '商品编号', unique: 'agency_pid_goods_id'},
    couponLink: {type: Sequelize.STRING(190), allowNull: true, comments: '活动加密编号'}
}

/**
 * 淘客订单
 */
exports.TaokeOrders = {
    auctionId: {
        type: Sequelize.STRING(160),
        allowNull: true,
        comments: '商品ID',
        unique: 'auctionId_taobaoTradeParentId'
    },
    auctionNum: {type: Sequelize.INTEGER, allowNull: true, comments: '商品数'},
    auctionTitle: {type: Sequelize.STRING(190), allowNull: true, comments: '商品信息'},
    auctionUrl: {type: Sequelize.STRING(190), allowNull: true, comments: '商品地址'},
    pictUrl: {type: Sequelize.STRING(190), allowNull: true, comments: '商品图片'},

    exMemberId: {type: Sequelize.STRING(160), allowNull: true, comments: '掌柜旺旺'},
    exNickName: {type: Sequelize.STRING(160), allowNull: true, comments: '掌柜旺旺'},
    exShopTitle: {type: Sequelize.STRING(160), allowNull: true, comments: '所属店铺'},
    shopTitle: {type: Sequelize.STRING(160), allowNull: true, comments: '订单类型'},

    createTime: {type: Sequelize.DATE, allowNull: true, comments: '创建时间'},
    clickTime: {type: Sequelize.DATE, allowNull: true, comments: '点击时间'},
    earningTime: {type: Sequelize.DATE, allowNull: true, comments: '结算时间'},

    feeString: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '效果预估'},
    tkPubShareFeeString: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '预估收入'},

    discountAndSubsidyToString: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '收入比率'},
    finalDiscountToString: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '佣金比率'},
    finalSubsidyToString: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '补贴比率'},

    discountFeeString: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '佣金金额'},
    subsidyFeeString: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '补贴金额'},

    payPrice: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '商品单价'},
    realPayFeeString: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '结算金额'},
    totalAlipayFeeString: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '付款金额'},

    shareRate: {type: Sequelize.STRING(30), allowNull: true, comments: '分成比率'},
    payStatus: {type: Sequelize.STRING(30), allowNull: true, comments: '订单状态, 订单失效, 订单付款, 订单结算'},
    taobaoTradeParentId: {
        type: Sequelize.STRING(160),
        allowNull: true,
        comments: '订单编号',
        unique: 'auctionId_taobaoTradeParentId'
    },
    terminalType: {type: Sequelize.STRING(30), allowNull: true, comments: '成交平台'},

    mediumId: {type: Sequelize.STRING(30), allowNull: true, comments: '来源媒体ID'},
    mediumName: {type: Sequelize.STRING(30), allowNull: true, comments: '来源媒体名称'},
    adPositionId: {type: Sequelize.STRING(30), allowNull: true, comments: '广告位ID'},
    adPositionName: {type: Sequelize.STRING(30), allowNull: true, comments: '广告位名称'},

    thirdParty: {type: Sequelize.STRING(60), allowNull: true, comments: '第三方服务来源'},
    postBy: {type: Sequelize.STRING(60), allowNull: true, comments: '获取数据方式'},

    tao_user: {type: Sequelize.STRING(160), allowNull: true, comments: '淘宝用户名'},
    partner_id: {type: Sequelize.INTEGER, allowNull: true, comments: '合伙人编号'},
    agency_id: {type: Sequelize.INTEGER, allowNull: true, comments: '代理编号'},
    inviter_agency_id: {type: Sequelize.INTEGER, allowNull: true, comments: '上级代理编号'},
    inviter_id: {type: Sequelize.INTEGER, allowNull: true, comments: '邀请者编号'},
    user_id: {type: Sequelize.INTEGER, allowNull: true, comments: '用户编号'},

    pay_amount: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '返款金额'},
    inviter_pay_amount: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '邀请人返款金额'},

    agency_amount: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '代理分成金额'},
    inviter_agency_amount: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '上级代理分成金额'},

    is_sham: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '是否虚假'},
    is_amount: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '是否入账，返现进入账号冻结(用户和邀请人)'},
    is_settle: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '是否结算，返现进入账号余额'},
    is_payed: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '返款是否支付'},
    is_back: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '订单无效, 是否返回'},

    agency_settle_id: {type: Sequelize.INTEGER, allowNull: true, comments: '代理结算编号(代理和上级代理)'},
    agency_back_id: {type: Sequelize.INTEGER, allowNull: true, comments: '订单无效, 代理结算编号, 在哪次结算返回扣回'},

    status: {
        type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Pending',
        validate: {isIn: [['Pending', 'Related']]}
    }
}

/**
 * 订单维权
 */
exports.TaokeRefunds = {
    tbAuctionId: {type: Sequelize.STRING(160), allowNull: true, comments: '商品ID'},
    tbAuctionTitle: {type: Sequelize.STRING(190), allowNull: true, comments: '商品标题'},
    tbAuctionNum: {type: Sequelize.INTEGER, allowNull: true, comments: '商品数'},
    tbSellerShopTitle: {type: Sequelize.STRING(190), allowNull: true, comments: '店铺'},

    refundCreateTime: {type: Sequelize.DATE, allowNull: true, comments: '创建时间'},
    refundFinishTime: {type: Sequelize.DATE, allowNull: true, comments: '完成时间'},
    earningTime: {type: Sequelize.DATE, allowNull: true, comments: '结算时间'},

    tbTradeParentId: {
        type: Sequelize.STRING(160),
        allowNull: true,
        comments: '订单编号',
        unique: 'auctionId_taobaoTradeParentId_tbTradeId'
    },
    tbTradeId: {
        type: Sequelize.STRING(160),
        allowNull: true,
        comments: '子订单编号',
        unique: 'auctionId_taobaoTradeParentId_tbTradeId'
    },

    refundFee: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '维权退款金额'},
    tkCommissionFee: {type: Sequelize.DECIMAL(10, 2), allowNull: true},
    tkSubsidyFee: {type: Sequelize.DECIMAL(10, 2), allowNull: true},
    showReturnFee: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '应返还金额'},
    tbTradeFinishPrice: {type: Sequelize.DECIMAL(10, 2), allowNull: true},

    showRefundStatus: {type: Sequelize.STRING(30), allowNull: true, comments: '状态'},
    showRefundReason: {type: Sequelize.STRING(30), allowNull: true, comments: '退款原因'},

    partner_id: {type: Sequelize.INTEGER, allowNull: true, comments: '合伙人编号'},
    agency_id: {type: Sequelize.INTEGER, allowNull: true, comments: '代理编号'},
    inviter_agency_id: {type: Sequelize.INTEGER, allowNull: true, comments: '上级代理编号'},
    inviter_id: {type: Sequelize.INTEGER, allowNull: true, comments: '邀请者编号'},
    user_id: {type: Sequelize.INTEGER, allowNull: true, comments: '用户编号'},

    is_back: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '订单无效, 是否返回'},
    status: {
        type: Sequelize.STRING(30),
        allowNull: false,
        defaultValue: 'Pending',
        validate: {isIn: [['Pending', 'Related']]}
    }
}

/**
 * 京东订单
 */
exports.JDOrders = {
    orderId: {
        type: Sequelize.STRING(30),
        allowNull: true,
        comments: '订单号',
        unique: 'orderId'
    },
    unionId: {type: Sequelize.STRING(30), allowNull: true, comments: '联盟编号'},
    orderDate: {type: Sequelize.DATE, allowNull: true, comments: '创建时间'},
    finishDate: {type: Sequelize.DATE, allowNull: true, comments: '点击时间'},
    cosPrice: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '支付金额'},
    commission: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '佣金'},
    num: {type: Sequelize.INTEGER(6), allowNull: true, comments: '数量'},
    returnNum: {type: Sequelize.INTEGER(6), allowNull: true, comments: '退款数量'},
    afterSaleNum: {type: Sequelize.INTEGER(6), allowNull: true},

    orderStatus: {type: Sequelize.INTEGER(6), allowNull: true},
    balance: {type: Sequelize.STRING(50), allowNull: true},
    split: {type: Sequelize.INTEGER(6), allowNull: true},
    yn: {type: Sequelize.INTEGER(6), allowNull: true},
    spId: {type: Sequelize.STRING(30), allowNull: true, comments: 'pid'},
    sourceEmt: {type: Sequelize.INTEGER(6), allowNull: true},
    orderEmt: {type: Sequelize.INTEGER(6), allowNull: true},
    refStatus: {type: Sequelize.INTEGER(6), allowNull: true},
    clearStatus: {type: Sequelize.STRING(50), allowNull: true},
    plus: {type: Sequelize.INTEGER(6), allowNull: true},
    plusName: {type: Sequelize.STRING(30), allowNull: true},
    spName: {type: Sequelize.STRING(30), allowNull: true},
    sourceEmtName: {type: Sequelize.STRING(30), allowNull: true},
    orderEmtName: {type: Sequelize.STRING(30), allowNull: true},
    accountDateStr: {type: Sequelize.STRING(60), allowNull: true},
    ynName: {type: Sequelize.STRING(30), allowNull: true},
    ynDetail: {type: Sequelize.STRING(30), allowNull: true},
    splitName: {type: Sequelize.STRING(30), allowNull: true},
    balanceName: {type: Sequelize.STRING(30), allowNull: true},
    orderStatusName: {type: Sequelize.STRING(30), allowNull: true},
    parentId: {type: Sequelize.STRING(30), allowNull: true},
    skus: {type: Sequelize.TEXT, allowNull: true, comments: '商品数据'},

    jd_user: {type: Sequelize.STRING(160), allowNull: true, comments: '京东用户名'},
    partner_id: {type: Sequelize.STRING(30), allowNull: true, comments: '合伙人编号'},
    agency_id: {type: Sequelize.STRING(30), allowNull: true, comments: '代理编号'},
    inviter_agency_id: {type: Sequelize.STRING(30), allowNull: true, comments: '上级代理编号'},
    inviter_id: {type: Sequelize.STRING(30), allowNull: true, comments: '邀请者编号'},
    user_id: {type: Sequelize.INTEGER, allowNull: true, comments: '用户编号'},

    pay_amount: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '返款金额'},
    inviter_pay_amount: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '邀请人返款金额'},

    agency_amount: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '代理分成金额'},
    inviter_agency_amount: {type: Sequelize.DECIMAL(10, 2), allowNull: true, comments: '上级代理分成金额'},

    is_sham: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '是否虚假'},
    is_amount: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '是否入账，返现进入账号冻结(用户和邀请人)'},
    is_settle: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '是否结算，返现进入账号余额'},
    is_payed: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '返款是否支付'},
    is_back: {type: Sequelize.INTEGER(1), allowNull: false, defaultValue: 0, comments: '订单无效, 是否返回'},

    agency_settle_id: {type: Sequelize.INTEGER, allowNull: true, comments: '代理结算编号(代理和上级代理)'},
    agency_back_id: {type: Sequelize.INTEGER, allowNull: true, comments: '订单无效, 代理结算编号, 在哪次结算返回扣回'},

    status: {
        type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Pending',
        validate: {isIn: [['Pending', 'Related']]}
    }
}

/**
 * 订单日志表
 */
exports.TaokeOrdersLogs = {
    opt: {type: Sequelize.STRING(100), allowNull: true, comments: '操作'},
    reference: {type: Sequelize.INTEGER, allowNull: true, comments: '引用的ID'},
    ext_data: {type: Sequelize.TEXT, allowNull: true, comments: '扩展数据'},
    user_id: {type: Sequelize.INTEGER, allowNull: true, comments: '操作人员'}
}

/**
 * 维权订单日志表
 */
exports.TaokeRefundsLogs = {
    opt: {type: Sequelize.STRING(100), allowNull: true, comments: '操作'},
    reference: {type: Sequelize.INTEGER, allowNull: true, comments: '引用的ID'},
    ext_data: {type: Sequelize.TEXT, allowNull: true, comments: '扩展数据'},
    user_id: {type: Sequelize.INTEGER, allowNull: true, comments: '操作人员'}
}

/**
 * 订单日志表
 */
exports.JDOrdersLogs = {
    opt: {type: Sequelize.STRING(100), allowNull: true, comments: '操作'},
    reference: {type: Sequelize.INTEGER, allowNull: true, comments: '引用的ID'},
    ext_data: {type: Sequelize.TEXT, allowNull: true, comments: '扩展数据'},
    user_id: {type: Sequelize.INTEGER, allowNull: true, comments: '操作人员'}
}

/**
 * 用户订单
 */
exports.UserOrders = {
    taobaoTradeParentId: {type: Sequelize.STRING(160), allowNull: true, comments: '订单号', unique: 'taobaoTradeParentId'},
    user_id: {type: Sequelize.INTEGER, allowNull: false, comments: '订单用户编号'},
    status: {
        type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Pending',
        validate: {isIn: [['Pending', 'Related', 'Delete']]}
    }
}

/**
 * 京东用户订单
 */
exports.JDUserOrders = {
    orderId: {type: Sequelize.STRING(160), allowNull: true, comments: '订单号', unique: 'orderId'},
    user_id: {type: Sequelize.INTEGER, allowNull: false, comments: '订单用户编号'},
    status: {
        type: Sequelize.STRING(30), allowNull: false, defaultValue: 'Pending',
        validate: {isIn: [['Pending', 'Related']]}
    }
}